package com.ruoyi.project.hcy.product.service.impl;

import com.ruoyi.project.hcy.product.mapper.ProFavoritesMapper;
import com.ruoyi.project.hcy.product.service.IProFavorites;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName ProFavoritesImpl
 * @Author SAI
 * @Date 2020/9/20 14:14
 * @Description ProFavoritesImpl
 * @Version 1.0
 */
@Service
public class ProFavoritesImpl implements IProFavorites {

    @Autowired
    private ProFavoritesMapper proFavoritesMapper;

    @Override
    public String checkFavoritesUnique(Long[] ids) {
        for (Long productId : ids) {
            if (proFavoritesMapper.checkFavoritesUnique(productId) != null) {
                return "1";
            }
        }
        return "0";
    }

    @Override
    public int addFavorites(Long[] productId) {
        int i = 0;
        for (Long aLong : productId) {
            try {
                proFavoritesMapper.addFavorites(aLong);
            } catch (Exception e) {
                e.printStackTrace();
                i = -1 ;
            }
        }
        return 1;
    }
}
